package ie.dcu.spca.view.user;

import ie.dcu.spca.Main;
import ie.dcu.spca.R;
import ie.dcu.spca.data.BasicDataManager;
import ie.dcu.spca.data.UserDataManager;
import ie.dcu.spca.view.CRUDDialog;
import android.content.DialogInterface;
import android.view.View;
import android.widget.EditText;

public class UserCRUDDialog extends CRUDDialog {

    private String name;
    private EditText usernameET;
    private static UserDataManager userManager;

    @Override
    protected void addOkButtonClickOpt(View v) {
        userManager.create(name);
    }

    @Override
    protected void bindWidgetOnCreate() {
        usernameET = ((EditText) findViewById(R.id.nameEditText));
    }

    @Override
    protected void deleteBeanOkButtonClickOpt(DialogInterface dialog) {
        userManager.delete(id);
    }

    @Override
    protected String getDeleteDataConfirmTip() {
        return this.getString(R.string.deleteUserConfirmTip) + name;
    }

    @Override
    protected boolean initializeValuesFromWidget() {
        name = usernameET.getText().toString();
        return true;
    }

    @Override
    protected void setValueFromIntentExtrasOnCreate() {
        userManager = Main.dataManager.userDataManager();
    }

    @Override
    protected void updateBeanWidgetInitialize() {
        name = bundle.getString(BasicDataManager.NAME);
        usernameET.setText(name);
    }

    @Override
    protected void updateOkButtonClickOpt(View v) {
        userManager.update(id, name);
    }
}
